//
//  Set_RootViewController.m
//  FruitHelper
//
//  Created by 赵隆杰 on 2021/12/10.
//

#import "Set_RootViewController.h"
#import "AboutViewController.h"
#import "SetTableViewCell.h"
#import "DailyReminderSheetView.h"

@interface Set_RootViewController ()

@end

@implementation Set_RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"设置";
    
    [self.view addSubview:self.tableView];
    
    self.tableView.estimatedRowHeight = 70;
    self.tableView.rowHeight = 70;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"SetTableViewCell" bundle:nil] forCellReuseIdentifier:@"SetTableViewCell"];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    UINavigationBar *navigationBar = self.navigationController.navigationBar;
    self.tableView.frame = CGRectMake(0, navigationBar.frame.origin.y, SL_WINDOW_WIDTH, SL_WINDOW_HEIGHT - navigationBar.frame.origin.y - SL_VC_TabBar_HEIGHT);
}

# pragma UITableViewDataSource, UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetTableViewCell" forIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:
        {
            cell.imageStr = @"dailyremind";
            cell.title = [NSString stringWithFormat:@"每日提醒"];
        }
            break;
        case 1:
        {
            cell.imageStr = @"about";
            cell.title = [NSString stringWithFormat:@"关于我"];
        }
            break;
        case 2:
        {
            cell.imageStr = @"evaluate";
            cell.title = [NSString stringWithFormat:@"去评价"];
        }
            break;
            
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        DailyReminderSheetView *addSheetView = [[DailyReminderSheetView alloc] initWithFrame:CGRectMake(0, 300, SL_WINDOW_WIDTH, SL_WINDOW_HEIGHT - 300)];
        [addSheetView show];
    } else if (indexPath.row == 1) {
        AboutViewController *vc = [[AboutViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 2) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://apps.apple.com/cn/app/id1600412388?mt=8"] options:@{} completionHandler:nil];
        
    }
}

@end
